package com.bookyourtrek.action;

import java.math.BigInteger;

import com.bookyourtrek.model.TicketModel;
import com.opensymphony.xwork2.ActionSupport;

public class ConfirmBookingAction extends ActionSupport {

	/**
	 * 
	 */
	private BigInteger ticketid;
	private double ticketprice;
	private double ticketfee;
	private Integer selectedquantity;
	private String tickettype;
	private double totalprice;
	
	private BigInteger adventureid;
	private Integer adventuretype;
	
	public BigInteger getAdventureid() {
		return adventureid;
	}

	public void setAdventureid(BigInteger adventureid) {
		this.adventureid = adventureid;
	}

	public Integer getAdventuretype() {
		return adventuretype;
	}

	public void setAdventuretype(Integer adventuretype) {
		this.adventuretype = adventuretype;
	}

	public double getTotalprice() {
		return totalprice;
	}

	public void setTotalprice(double totalprice) {
		this.totalprice = totalprice;
	}

	public BigInteger getTicketid() {
		return ticketid;
	}

	public void setTicketid(BigInteger ticketid) {
		this.ticketid = ticketid;
	}

	public double getTicketprice() {
		return ticketprice;
	}

	public void setTicketprice(double ticketprice) {
		this.ticketprice = ticketprice;
	}

	public double getTicketfee() {
		return ticketfee;
	}

	public void setTicketfee(double ticketfee) {
		this.ticketfee = ticketfee;
	}

	public Integer getSelectedquantity() {
		return selectedquantity;
	}

	public void setSelectedquantity(Integer selectedquantity) {
		this.selectedquantity = selectedquantity;
	}

	private static final long serialVersionUID = 1L;
	
	public String getTickettype() {
		return tickettype;
	}

	public void setTickettype(String tickettype) {
		this.tickettype = tickettype;
	}
	
	public String confirmbooking () {
		
		TicketModel ticketmodel = new TicketModel();
		if(ticketid == null) {
			return "goback";
		}
		Integer availablequantity = ticketmodel.gettotalticketquantity(ticketid) -
				ticketmodel.getbookedtikcetquantity(ticketid);
		
		//check weather selected quantity is available or not
		if(selectedquantity > availablequantity) {
			addFieldError("ticketnotavailable", "Sorry selected quantity of ticket is not available");
			return INPUT;
		}
		
		//calculate total price
		totalprice = ticketprice * selectedquantity + ticketfee * selectedquantity;
		

		return SUCCESS;
	}

	

}
